package com.qf.qfuser;

import com.qf.qfuser.conf.LoadBalanceConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableEurekaClient
//QF-ORDER服务的Ribbon负载均衡调用，使用LoadBalanceConfig.class中的规则
//@RibbonClient(value = "QF-ORDER",configuration = LoadBalanceConfig.class)
//@RibbonClients({
//        @RibbonClient(),
//        @RibbonClient()
//})
//开启Hystrix服务保护功能
@EnableCircuitBreaker
//开启Feign接口扫描
@EnableFeignClients
public class QfUserApplication {

    public static void main(String[] args) {
        SpringApplication.run(QfUserApplication.class, args);
    }

    /**
     * 在消费方向spring容器中注入一个发起远程HTTP访问的模板对象
     * @return
     */
    @Bean
    @LoadBalanced  //这个注解会向RestTemplate中添加一个LoadBalancerInterceptor
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

}
